Skip to content

feat: add randomSeed argument to COIN_CMD for reproducible CBC solves (#613) - #936

Open
haiiibin wants to merge 1 commit into
coin-or:masterfrom
haiiibin:feat/coin-random-seed
Open

feat: add randomSeed argument to COIN_CMD for reproducible CBC solves (#613)#936
haiiibin wants to merge 1 commit into
coin-or:masterfrom
haiiibin:feat/coin-random-seed

Conversation

@haiiibin

Copy link
Copy Markdown

Motivation

COIN_CMD already exposes threads, maxNodes, timeMode, gapRel, etc. as constructor arguments that translate to CBC command-line options, but the random seed (CBC's -randomSeed) could previously only be set through the generic options list, e.g. COIN_CMD(options=["randomSeed 20"]). Setting the seed is the standard way to make MIP solves reproducible (and can also change solve time), so it is worth exposing directly. This was requested in #613 and seconded there by a contributor.

Change

  • Add a randomSeed keyword argument to COIN_CMD.__init__. It flows into optionsDict like the other options and is emitted as -randomSeed <n> from getOptions, mirroring the existing threads / maxNodes handling.
  • Note: the issue also mentions PULP_CBC_CMD, but that class no longer exists; COIN_CMD is the current CBC entry point (and the default solver), so the argument lives there.

Verification

  • Confirmed CBC accepts -randomSeed <n> and solves to optimality (against PuLP's CBC binary).
  • Confirmed getOptions() emits randomSeed 20 when randomSeed=20 is set, so -randomSeed 20 appears on the solver command line.
  • Added test_random_seed (in COIN_CMD_CBCOptionsTest) mirroring the existing test_strong: it solves a small MIP with a seed, reads the command line back from the log file, and asserts -randomSeed 20 is present; it also asserts the constructor argument populates optionsDict.

Closes #613.

COIN_CMD exposes threads, maxNodes, timeMode, etc. as constructor arguments
that map to CBC command-line options, but the random seed (CBC's
-randomSeed) could previously only be set through the generic `options`
list. Controlling the seed is the standard way to make MIP solves
reproducible (and can also change solve time), so expose it directly.

Add a randomSeed keyword argument that flows into optionsDict and is emitted
as `-randomSeed <n>` via getOptions, mirroring the existing threads/maxNodes
handling. (PULP_CBC_CMD was removed, so COIN_CMD, the default CBC entry
point, is where this belongs.)

Add a test mirroring test_strong that solves with a seed and asserts
-randomSeed appears on the command line.
@CLAassistant

CLAassistant commented Jul 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add functional argument to CBC_CMD/COIN_CMD to allow setting random seed

2 participants